package com.demo.util;

import jdk.management.resource.internal.inst.SocketOutputStreamRMHooks;
import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName StringToDateConverter
 * @Description TODO
 * @Author Windy
 * @Date 2022/9/3 14:53
 * @Version 1.0
 **/
public class StringToDateConverter implements Converter<String, Date> {
    @Override
    public Date convert(String s) {
        System.out.println(s);
       if (s.isEmpty()){
           throw new NullPointerException("请输入要转换的日期");
       }
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            System.out.println(s);
            Date parse = dateFormat.parse(s);
            System.out.println(parse);
            return parse;
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }

    }
}
